package com.project.housesalesystem.exception;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.project.housesalesystem.common.Results;
<<<<<<< HEAD
import jakarta.servlet.http.HttpServletRequest;
=======
>>>>>>> 66dcee4e153c16ef05fd0c7e1ed9f414a0bf0bc9
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

<<<<<<< HEAD
=======
import javax.servlet.http.HttpServletRequest;
>>>>>>> 66dcee4e153c16ef05fd0c7e1ed9f414a0bf0bc9


@ControllerAdvice(basePackages = "com.project.housesalesystem.controller")
public class GlobalExceptionHandler {

    private static final Log log = LogFactory.get();


    //统一异常处理@ExceptionHandler,主要用于Exception
    @ExceptionHandler(Exception.class)
    @ResponseBody//返回json串
    public Results error(HttpServletRequest request, Exception e) {
        log.error("异常信息：", e);
        return Results.error();
    }

    @ExceptionHandler(CustomException.class)
    @ResponseBody//返回json串
    public Results customError(HttpServletRequest request, CustomException e) {
        return Results.error(e.getMsg());
    }

}
